<%@ tag import="com.biz.primus.base.tags.Layout" %>
<%@ tag pageEncoding="UTF-8" %>
<%@taglib prefix="b" tagdir="/WEB-INF/tags/base" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--标题--%>
<%@ attribute name="_title" required="true" type="java.lang.String" %>
<%--表单name--%>
<%@ attribute name="_name" required="false" type="java.lang.String" %>
<%--表单id--%>
<%@ attribute name="_id" required="false" type="java.lang.String" %>
<c:set var="_id" value="${empty _id ? _name : _id}"/>

<%--默认值--%>
<%@ attribute name="_value" required="false" type="java.lang.String" %>

<%--布局,可选single,twin,three三个值,对应单列,双列,三列--%>
<%@ attribute name="_layout" required="false" type="com.biz.primus.base.tags.Layout" %>
<c:set var="_layout" value="<%=_layout==null?Layout.single:_layout%>"/>

<%--是否允许插入图片--%>
<%@ attribute name="_allowedImg" description="功能性文本编辑生效时使用" required="false" type="java.lang.Boolean" %>

<%@ attribute name="_containerCol" required="false" type="java.lang.Integer" %>

<%@ attribute name="_editor" required="false" type="java.lang.Boolean" %>
<%@ attribute name="_textAreaClass" description="普通富文本框生效时使用" required="false" type="java.lang.String" %>
<%@ attribute name="_textAreaCol" description="普通富文本框生效时使用" required="false" type="java.lang.Integer" %>
<%@ attribute name="_titleCol" description="普通富文本框生效时使用" required="false" type="java.lang.Integer" %>
<c:set var="_titleCol" value="${empty _title?_layout.titleCol:_titleCol}"/>
<c:set var="_textAreaCol" value="${empty _textAreaCol?_layout.inputCol:_textAreaCol}"/>

<b:row layout="${_layout}">
    <c:choose>
        <c:when test="${empty _editor or _editor}">
            <c:if test="${not empty _title}">
                <h4 class="header green clearfix">${_title}</h4>
            </c:if>
            <div class="col-xs-${empty _containerCol?12:_containerCol}">
                <div class="wysiwyg-editor" id="${_id}">
                    <c:out value="${_value}"/>
                </div>
            </div>

            <script>
                jQuery(function ($) {
                    $("#${_id}").ace_wysiwyg({
                        toolbar: [
                            {name: 'font', title: '字体'},
                            null,
                            {name: 'fontSize', title: '字体大小'},
                            null,
                            {name: 'bold', title: '加粗'},
                            {name: 'italic', title: '斜体'},
                            {name: 'strikethrough', title: '删除线'},
                            {name: 'underline', title: '下划线'},
                            null,
                            {name: 'insertunorderedlist', title: '插入无序列表'},
                            {name: 'insertorderedlist', title: '插入有序列表'},
                            {name: 'outdent', title: '取消缩进'},
                            {name: 'indent', title: '缩进'},
                            null,
                            {name: 'justifyleft', title: '左对齐'},
                            {name: 'justifycenter', title: '居中对齐'},
                            {name: 'justifyright', title: '右对齐'},
                            {name: 'justifyfull', title: '两端对齐'},
                            null,
                            {name: 'createLink', title: '加入超链接', button_text: '加入'},
                            {name: 'unlink', title: '取消超链接'},
                            <c:if test="${_allowedImg or empty _allowedImg}">
                            {
                                name: 'insertImage', title: '插入图片', button_insert: '插入',
                                button_text: '浏览文件', placeholder: '图片地址'
                            },
                            </c:if>
                            null,
                            null,
                            {name: 'undo', title: '撤销上一步'},
                            {name: 'redo', title: '取消撤销'},
                            null,
                            {name: 'viewSource', title: '查看源码'}

                        ],
                        'wysiwyg': {
                            fileUploadError: function () {
                                layer.msg("图片上传失败", {icon: 5})
                            }
                        }
                    }).prev().addClass('wysiwyg-style2');
                })
            </script>
        </c:when>
        <c:otherwise>
            <b:label title="${_title}" forId="${_id}" titleCol="${_titleCol}"/>
            <div class="col-sm-${_textAreaCol}">
                <textarea style="resize: vertical;height: 100px" name="${_name}" id="${_id}"
                          class="col-sm-${_textAreaCol} ${_textAreaClass}">${_value}</textarea>
            </div>
        </c:otherwise>
    </c:choose>

</b:row>
